﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using Chinaer.Model.Common;
using Chinaer.Core.BaseCore.Extensions;

namespace Chinaer.TestService
{
    [TestFixture]
    public class TestChinaerService
    {
        private Chinaer.WCF.Services.ChinaerService chinaerService = null;

        public TestChinaerService()
        {
            chinaerService = new WCF.Services.ChinaerService();
        }
        /// <summary>
        /// 用户注册
        /// </summary>
        [Test]
        public void RegisterCustomer()
        {
            DTO.CustomerDTO customerDTO = new DTO.CustomerDTO()
            {
                LoginName = "guozhiqi",
                LoginPassword = "yuanjinzhou"
            };
            JsonResult jsonResult = chinaerService.RegisterCustomer(customerDTO);
            if (jsonResult.Success)
            {
                //表示注册成功
                Assert.AreEqual(jsonResult.Success, true);
            }
            else
            {
                //表示注册失败
                Chinaer.Core.BaseCore.LoginStatus loginStatus = jsonResult.LoginStatus;
                Assert.AreEqual(loginStatus.ToDescription(), "IsExists");
            }

        }
        /// <summary>
        /// 用户登录
        /// </summary>
        [Test]
        public void LoginCustomer()
        {
            DTO.CustomerDTO customerDTO = new DTO.CustomerDTO()
            {
                LoginName = "guozhiqi",
                LoginPassword = "yuanjinzhou"
            };
            DTO.CustomerDTO customerDTOResult = chinaerService.LoginCustomer(customerDTO);
            if (customerDTOResult.LoginStatus == Chinaer.Core.BaseCore.LoginStatus.Success)
            {
                //表示登录成功
                string spiToken = customerDTOResult.ApiToken;
                Assert.AreNotEqual(spiToken, null);
            }
            else
            {
                //表示登录失败
                string result = customerDTOResult.LoginStatus.ToDescription();
                Assert.AreEqual(result, Chinaer.Core.BaseCore.LoginStatus.UserNotExists.ToDescription());
            }
        }


        [Test]
        public void AddAddress()
        {
            DTO.AddressDTO addressDTO = new DTO.AddressDTO()
            {
                Address = "山东省单县",
                CityID = "11",
                CountryID = "11",
                Description = "这是在测试信息中创建的描述信息",
                Receiver = "袁金舟",
                ProvinceID = "11",
                ZipCode = "4456256",
                ReceiverPhone = "0530-4456256",
                ReceiverMobile = "13153030544"
            };
            JsonResult jsonResult = chinaerService.AddAddress(addressDTO);
            if (jsonResult.Success)
            {
                //表示创建成功
                Assert.AreEqual(jsonResult.Success, true);
            }
            else
            {
                //表示创建失败
                Chinaer.Core.BaseCore.LoginStatus loginStatus = jsonResult.LoginStatus;
                Assert.AreEqual(loginStatus, Chinaer.Core.BaseCore.LoginStatus.NonLogin);

            }

        }

        [Test]
        public void AddShangJia()
        {
            DTO.ShangJiaDTO shangJiaDTO = new DTO.ShangJiaDTO()
            {
                LoginName = "www",
                LoginPassword = "www"

            };
            JsonResult jsonResult = chinaerService.RegisterShangJia(shangJiaDTO);
            Assert.AreEqual(jsonResult.Success, true);
        }
        [Test]
        public void LoginShangJia()
        {
            DTO.ShangJiaDTO shangJiaDTO = new DTO.ShangJiaDTO()
            {
                LoginName = "www",
                LoginPassword = "www"
            };
            DTO.ShangJiaDTO shangJiaDTO1 = chinaerService.LoginShangJia(shangJiaDTO);
            Assert.AreEqual(shangJiaDTO1.LoginName, "www");

        }
        [Test]
        public void AddCountry()
        {


        }

        [Test]
        public void AddException()
        {
            DivideByZeroException exception = new DivideByZeroException();
            Bll.ExceptionRepository.AddException(exception);
        }

        [Test]
        public void AddZhongXinGongGao()
        {
            DTO.ZhongXinGongGaoDTO zhongXinGongGaoDTO = new DTO.ZhongXinGongGaoDTO()
            {
                Content = "公告内容",
                CreateTime = DateTime.Now,
                EndTime = DateTime.Now.AddDays(100)

            };
            Model.Common.JsonResult jsonResult = chinaerService.AddZhongXinGongGao(zhongXinGongGaoDTO);
            Assert.AreEqual(jsonResult.Success,true);
        }
        [Test]
        public void GetAllZhongXinGongGao()
        {
            List<DTO.ZhongXinGongGaoDTO> zhongXinGongGao = chinaerService.GetAllZhongXinGongGao("20131116224803512848fbd856042405", "222");
            Assert.AreEqual(zhongXinGongGao.Count, 1);

        }
        public string CheckJsonResult(JsonResult jsonResult)
        {
            string result = string.Empty;
            if (jsonResult.Success == false)
            {
                return jsonResult.LoginStatus.ToDescription();
            }
            return "";
        }

    }
}
